package com.mdd.admin.controller;

import com.mdd.admin.aop.Log;
import com.mdd.admin.service.IOrderUrgeMsgService;
import com.mdd.admin.validate.commons.IdValidate;
import com.mdd.admin.validate.OrderUrgeMsgCreateValidate;
import com.mdd.admin.validate.OrderUrgeMsgUpdateValidate;
import com.mdd.admin.validate.OrderUrgeMsgSearchValidate;
import com.mdd.admin.validate.commons.PageValidate;
import com.mdd.admin.vo.OrderUrgeMsgListedVo;
import com.mdd.admin.vo.OrderUrgeMsgDetailVo;
import com.mdd.common.core.AjaxResult;
import com.mdd.common.core.PageResult;
import com.mdd.common.validator.annotation.IDMust;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("api/urgeMsg")
@Api(tags = "订单催发货消息管理")
public class OrderUrgeMsgController {

    @Resource
    IOrderUrgeMsgService iOrderUrgeMsgService;

    @GetMapping("/list")
    @ApiOperation(value="订单催发货消息列表")
    public AjaxResult<PageResult<OrderUrgeMsgListedVo>> list(@Validated PageValidate pageValidate,
                                                     @Validated OrderUrgeMsgSearchValidate searchValidate) {
        PageResult<OrderUrgeMsgListedVo> list = iOrderUrgeMsgService.list(pageValidate, searchValidate);
        return AjaxResult.success(list);
    }

    @GetMapping("/detail")
    @ApiOperation(value="订单催发货消息详情")
    public AjaxResult<OrderUrgeMsgDetailVo> detail(@Validated @IDMust() @RequestParam("id") Integer id) {
        OrderUrgeMsgDetailVo detail = iOrderUrgeMsgService.detail(id);
        return AjaxResult.success(detail);
    }

    @Log(title = "订单催发货消息新增")
    @PostMapping("/add")
    @ApiOperation(value="订单催发货消息新增")
    public AjaxResult<Object> add(@Validated @RequestBody OrderUrgeMsgCreateValidate createValidate) {
        iOrderUrgeMsgService.add(createValidate);
        return AjaxResult.success();
    }

    @Log(title = "订单催发货消息编辑")
    @PostMapping("/edit")
    @ApiOperation(value="订单催发货消息编辑")
    public AjaxResult<Object> edit(@Validated @RequestBody OrderUrgeMsgUpdateValidate updateValidate) {
        iOrderUrgeMsgService.edit(updateValidate);
        return AjaxResult.success();
    }

    @Log(title = "订单催发货消息删除")
    @PostMapping("/del")
    @ApiOperation(value="订单催发货消息删除")
    public AjaxResult<Object> del(@Validated @RequestBody IdValidate idValidate) {
        iOrderUrgeMsgService.del(idValidate.getId());
        return AjaxResult.success();
    }

}
